/**
 * Copyright 2018-2019 jianggujin (www.jianggujin.com).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jianggujin.modulelink.support;

import java.util.Map;

import com.jianggujin.modulelink.exception.JBeanNotFoundException;

/**
 * Bean提供者服务
 * 
 * @author jianggujin
 *
 */
public interface JBeanProvider {
    /**
     * 通过类对象获得Bean
     * 
     * @param <T>
     * @param requiredType
     * @return
     * @throws JBeanNotFoundException
     */
    <T> T getBean(Class<T> requiredType) throws JBeanNotFoundException;

    /**
     * 通过类对象获得Bean，如果有多个Bean符合条件，取查到的第一个，多次调用返回值不保证一致，未找到则返回null
     * 
     * @param <T>
     * @param requiredType
     * @return
     */
    <T> T optBean(Class<T> requiredType);

    /**
     * 通过名称获得Bean
     * 
     * @param name
     * @return
     * @throws JBeanNotFoundException
     */
    Object getBean(String name) throws JBeanNotFoundException;

    /**
     * 通过名称获得Bean，未找到则返回null
     * 
     * @param name
     * @return
     */
    Object optBean(String name);

    /**
     * 通过名称和类型获得Bean
     * 
     * @param <T>
     * @param name
     * @param requiredType
     * @return
     * @throws JBeanNotFoundException
     */
    <T> T getBean(String name, Class<T> requiredType) throws JBeanNotFoundException;

    /**
     * 通过名称和类型获得Bean，未找到则返回null
     * 
     * @param <T>
     * @param name
     * @param requiredType
     * @return
     */
    <T> T optBean(String name, Class<T> requiredType);

    /**
     * 获得指定类型Bean所有名称
     * 
     * @param requiredType
     * @return
     * @throws JBeanNotFoundException
     */
    String[] getBeanNamesForType(Class<?> requiredType) throws JBeanNotFoundException;

    /**
     * 获得指定类型Bean所有名称
     * 
     * @param requiredType
     * @return
     */
    String[] optBeanNamesForType(Class<?> requiredType);

    /**
     * 通过类型获得所有Bean
     * 
     * @param <T>
     * @param requiredType
     * @return
     * @throws JBeanNotFoundException
     */
    <T> Map<String, T> getBeansOfType(Class<T> requiredType) throws JBeanNotFoundException;

    /**
     * 通过类型获得所有Bean
     * 
     * @param <T>
     * @param requiredType
     * @return
     */
    <T> Map<String, T> optBeansOfType(Class<T> requiredType);
}
